<?php
/**
 * Created by PhpStorm.
 * User: chenshiqi
 * Date: 2018/9/11
 * Time: 17:28
 */

namespace app\common\model;

/**
 * 用户群组模型类
 */
class UserGroup extends Common
{
    public function getUserGroup($user_id)
    {
        return $this->alias('ug')
            ->join(['chat_group'=>'g'],'ug.group_id = g.id')
            ->where(['ug.user_id'=>$user_id])
            ->field('g.id,g.groupname,g.avatar,g.group_size,g.group_count')
            ->select();
    }

    public function getMemberIds($group_id){
        return $this->where(['group_id'=>$group_id])->field('user_id')->select();
    }

    public function getMembers($group_id){
        return $this->alias('ug')
            ->join(['chat_user'=>'u'],'ug.user_id = u.id')
            ->where(['ug.group_id'=>$group_id])
            ->field('u.id,u.username,u.avatar,u.sign')
            ->select();
    }
}